package URL;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

public class Urldemo {

	public static void main(String[] args) {
		try {
			URL url = new URL("http://news.qq.com/a/20170320/006038.htm");
			System.out.println(url.getProtocol());
			System.out.println(url.getHost());
			System.out.println(url.getPort());
			System.out.println(url.getFile());
			URLConnection uc = url.openConnection();
			InputStream in = uc.getInputStream();
			BufferedReader br = new BufferedReader(new InputStreamReader(in, "gb2312"));
			String s = br.readLine();
			while (s!= null) {
				System.out.println(s);
				s = br.readLine();
			}
		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

}
